package com.automannn.seataSamples.account.service.impl;

import com.automannn.seataSamples.account.entity.AccountPO;
import com.automannn.seataSamples.account.mapper.AccountMapper;
import com.automannn.seataSamples.account.service.IAccountService;
import com.automannn.seataSamples.api.dto.AccountDTO;
import com.automannn.seataSamples.api.response.ObjectResponse;
import com.automannn.seataSamples.api.response.ResponseStatusEnum;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author automannn
 * @Date 2022/3/24
 */
@Service
public class IAccountServiceImpl extends ServiceImpl< AccountMapper,AccountPO> implements IAccountService {

    @Override
    public ObjectResponse decreaseAccount(AccountDTO accountDTO) {
        int account = baseMapper.decreaseAccount(accountDTO.getUserId(), accountDTO.getAmount().doubleValue());
        ObjectResponse<Object> response = new ObjectResponse<>();
        if (account > 0) {
            response.setStatus(ResponseStatusEnum.SUCCESS.getCode());
            response.setMessage(ResponseStatusEnum.SUCCESS.getMessage());
            return response;
        }

        response.setStatus(ResponseStatusEnum.FAIL.getCode());
        response.setMessage(ResponseStatusEnum.FAIL.getMessage());
        return response;
    }
}
